const app = getApp()

Component({
    /**
     * 组件的属性列表
     */
    properties: {
        couponConfig: {
            type: Object,
            value: {
                background: "",
                themeColor: "",
                loadNumber: 3
            }
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        couponInfoList: []
    },

    ready: function () {
        this.getData()
    },

    /**
     * 组件的方法列表
     */
    methods: {
        getData() {
            var that = this;
            var data = {
                searchCount: false,
                current: 1,
                size: this.properties.couponConfig.loadNumber ? this.properties.couponConfig.loadNumber : 3,
                ascs: 'sort', //升序字段
                descs: ''
            };
            app.api.couponInfoPage(data).then(function (res) {
                that.setData({
                    couponInfoList: res.data.records || []
                });
            });
        },
        couponUserSave(e) {
            var that = this;
            app.api.couponUserSave({
                couponId: e.currentTarget.dataset.id
            }).then(function (res) {
                wx.showToast({title: '领取成功', icon: 'success', duration: 2000});
                that.getData();
            });
        }
    }
})
